﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics.Contracts;

namespace Konst3d.Efficiency.Impl.SparsedBinary
{
    public /*internal*/ class ListFileLayoutInt: IListFileLayout<int>
    {
        public int ByteSize
        {
            get
            {
                return 4;
            }
        }

        public void Write(int value, BinaryWriter writer, int offset = -1, SeekOrigin origin = SeekOrigin.Begin)
        {
            Contract.Requires(writer != null);

            if (offset >= 0)
            {
                writer.Write(value, offset, origin);
            }
            else
            {
                writer.Write(value);
            }
        }

        public int Read(BinaryReader reader, int offset = -1, SeekOrigin origin = SeekOrigin.Begin)
        {
            Contract.Requires(reader != null);

            int result;

            if (offset >= 0)
            {
                result = reader.ReadInt32(offset, origin);
            }
            else
            {
                result = reader.ReadInt32();
            }

            return result;
        }

        public bool Equals(int arg1, int arg2)
        {
            return arg1 == arg2;
        }

        public int Compare(int arg1, int arg2)
        {
            int result = 0;

            if (arg1 != arg2)
            {
                result = arg1 > arg2 ? 1 : -1;
            }

            return result;
        }
    }
}
